package com.test.travelinformation.adapter;

import android.content.Context;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.test.travelinformation.R;

import java.util.List;


public class UpImageAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private Context context;

    public UpImageAdapter(Context context, List<String> data) {
        super(R.layout.item_up_image, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, String s) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12+12, context.getResources().getDisplayMetrics());
        final View itemView = holder.getView(R.id.ll_content);
        //AutoUtils.autoSize(itemView);
        itemView.post(new Runnable() {
            @Override
            public void run() {
                // LogUtils.e("设置了图片的高度比例");
                ViewGroup.LayoutParams params = itemView.getLayoutParams();
                params.width=(width-padding)/3;
                params.height = params.width;
                itemView.setLayoutParams(params);
            }
        });
        ImageView imageView = holder.getView(R.id.iv_up_item);
        Glide.with(context)
                .load(s)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(25)))//圆角半径
                .skipMemoryCache(true) // 不使用内存缓存
                .diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
                .into(imageView);
    }
}